#!/usr/bin/env bash
export HOST0=172.16.2.200
export HOST1=172.16.2.201
export HOST2=172.16.2.202
ETCDHOSTS=(${HOST0} ${HOST1} ${HOST2})
NAMES=("k8s-etcd-01" "k8s-etcd-02" "k8s-etcd-03")
for i in "${!ETCDHOSTS[@]}"; do
HOST=${ETCDHOSTS[$i]}
NAME=${NAMES[$i]}
mkdir -p /tmp/{$HOST0,$HOST1,$HOST2}
cat << EOF > /tmp/${HOST}/kubeadmcfg.yaml
apiVersion: "kubeadm.k8s.io/v1beta1"
kind: ClusterConfiguration
etcd:
    local:
        serverCertSANs:
        - "${HOST0}"
        - "${HOST1}"
        - "${HOST2}"
        - "k8s-etcd-01"
        - "k8s-etcd-02"
        - "k8s-etcd-03"
        - "apiverser01.1ziton.com"
        - "nginx-kubernetes-server"
        - "k8s-master-01"
        - "k8s-master-02"
        - "k8s-master-03"
        - "k8s-master-04"
        - "k8s-master-05"
        peerCertSANs:
        - "${HOST0}"
        - "${HOST1}"
        - "${HOST2}"
        - "k8s-etcd-01"
        - "k8s-etcd-02"
        - "k8s-etcd-03"
        - "apiverser01.1ziton.com"
        - "k8s-master-01"
        - "k8s-master-02"
        - "k8s-master-03"
        - "k8s-master-04"
        - "k8s-master-05"
        extraArgs:
            initial-cluster: ${NAMES[0]}=https://${ETCDHOSTS[0]}:2380,${NAMES[1]}=https://${ETCDHOSTS[1]}:2380,${NAMES[2]}=https://${ETCDHOSTS[2]}:2380
            initial-cluster-state: new
            name: ${NAME}
            listen-peer-urls: https://${HOST}:2380
            listen-client-urls: https://${HOST}:2379
            advertise-client-urls: https://${HOST}:2379
            initial-advertise-peer-urls: https://${HOST}:2380
        dataDir: /data/etcd
imageRepository: registry.aliyuncs.com/google_containers
kubernetesVersion: v1.13.8
EOF
done
